package com.example.module_repair.repairnet

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.example.lib_common.base.BaseViewModel
import com.example.module_repair.repair_orders.model.CraeateRepairOrderModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject


@HiltViewModel
class RepairViewModel @Inject constructor(private val repairRePo: RepairRePo) : BaseViewModel() {

    // 获取 报修单
//    val _repairOrdsFlow = MutableStateFlow<List<RepairModel>>(emptyList())
//    val repairOrdsFlow: StateFlow<List<RepairModel>> = _repairOrdsFlow

    val repairOrds = MutableLiveData<List<RepairModel>>()
    fun getRepairOrders() {
        execute(
            action = repairRePo.getRepairOrders(),
            onFinish = {
                repairOrds.value = it.data
//                _repairOrdsFlow.value = it.data
            },
            onError = {
                repairRePo.getRepairOrders()
            }
        )
    }


    //  创建 报修单
    val _createRepairOrderlivedata = MutableLiveData<String>()
    fun createRepairOrders(createrepairoremodel: CraeateRepairOrderModel) {
        execute(
            action = repairRePo.createRepairOrders(createrepairoremodel),
            onFinish = {
                _createRepairOrderlivedata.value = it.data
                Log.d("createorder", "createRepairOrders: " + it.message + it.data)
            },
            onError = {
                repairRePo.createRepairOrders(createrepairoremodel)
            }
        )
    }


}